package main.java.com.huang;


import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * @author HuangShen
 * @Description
 * @create 2021-04-04 8:43
 */
public class TestMongoDBClient {



    @Test
    public void  test(){



        MongoClient mongoClient = new MongoClient("182.92.221.225", 27017);

        MongoDatabase database = mongoClient.getDatabase("MyTest");

        MongoCollection<Document> hhh = database.getCollection("hhh");
        Document document = new Document();
        document.put("name","huangshen");
        FindIterable<Document> documents = hhh.find(document);
        for (Document document1 : documents) {
            System.out.println(document1.get("_id"));
            System.out.println(document1.get("name"));
            System.out.println(document1.get("age"));
        }

        System.out.println(database);
        mongoClient.close();
    }
}
